<?php // echo CHtml::errorSummary($model); ?>
<div style="clear: both;">
    <?php echo CHtml::beginForm('', 'post', array('class' => 'dot_form fw_20', 'enctype'=>'multipart/form-data')); ?>
    <fieldset>
        <legend><?php echo Yii::t('common', 'please_fill_table_contents'); ?></legend>
        <dl>
            <dt><?php echo CHtml::activeLabelEx($model, 'parent_id'); ?></dt>
            <dd>
                <div>
                <?php
                require_once(Yii::app()->basePath . '/extensions/GraphTree/tree.php');
                $datas = MediaCategory::model()->getCTreeViewDatas();
//                CVarDumper::dump($datas, 30, true);
//                exit;
                if (count($datas) && $datas !== null) {
                    $datas = dumpArrayTree($datas);
                }
//                CVarDumper::dump($datas, 30, true);
                $trees = array('1' => 'ΞΞ NODE ROOT ΞΞ');
                if (count($datas)) {
                    foreach ($datas as $data) {
                        $trees[$data['id']] = $data['levelstr'] . '⇒ ' . strip_tags($data['text']) . '《' . (string)$data['order_pos'] . '》';
                    }
                }
                echo CHtml::activeDropDownList($model, 'parent_id', $trees);
                ?>
                </div>
                <div><?php echo CHtml::error($model, 'parent_id'); ?></div>
            </dd>
            <dt><?php echo CHtml::activeLabelEx($model, 'name'); ?></dt>
            <dd>
                <div><?php
                    echo CHtml::activeTextField($model, 'name', array(
                        'size' => 60,
                        'maxlength' => 200
                    ));
                    ?>
                </div>
                <?php echo CHtml::error($model, 'name'); ?>
            </dd>
            <dt><?php echo CHtml::activeLabelEx($model, 'order_pos'); ?></dt>
            <dd>
                <div><?php echo CHtml::activeDropDownList($model, 'order_pos', MediaCategory::model()->orderPosOptions); ?></div>
                <?php echo CHtml::error($model, 'order_pos'); ?>
            </dd>
            <dt></dt>
            <dd>
                <?php
                echo CHtml::activeHiddenField($model, 'id');
                echo CHtml::submitButton($update
                    ? Yii::t('common', 'update') : Yii::t('common', 'save'), array(
                    'class' => 'btn'
                ));
                ?>
            </dd>
        </dl>
    </fieldset>
    <?php echo CHtml::endForm(); ?>
</div>

<?php if ($update): ?>
<div>
     <?php
    echo CHtml::beginForm(array('mediaCategories/delete', 'id' => $model->id), 'post', array(
        'class' => 'dot_form fw_50',
        'onsubmit' => "return confirm('" . Yii::t('mediaCategory', 'delete_node_confirm_message', array('node_name' => $model->name)) . "');",
    ));
    ?>
    <p>
        <?php
        echo CHtml::radioButtonList('delete_range', 0, array(
            Yii::t('mediaCategory', 'delete_node_only_self', array('node_name' => $model->name)),
            Yii::t('mediaCategory', 'delete_node_with_all_subs', array('node_name' => $model->name))
        ));
        ?>
        </p>
        <p>
            <?php echo CHtml::submitButton(Yii::t('common', 'delete')); ?>
        </p>
        <?php echo CHtml::endForm(); ?>
</div>
<?php endif; ?>